package PimpDBManager;

import java.io.*;
import java.io.PrintStream;
import java.util.logging.Level;
import java.util.logging.Logger;
import nu.xom.*;

class DBManager
{
    private String server_addr = "localhost";
    private int server_port = 5000;
    private static String save_dir = "\\saved\\";
    private static String save_file_name = "pimp";
    private static PrintStream xmldoc;
    private static String path;
    
    public void saveToFile()
    {

    }
    public void saveToServer()
    {

    }
    public static void main(String[] args)
    {
        Element root = new Element("root");
        Element event = new Element("event");
        //event.addAttribute(new Attribute("date","13.07.2007"));
        Element temp = new Element("whoah");
        temp.appendChild("spotkanie z kims tam");
        event.appendChild(temp);
        root.appendChild(event);
        event = new Element("event");
        //event.addAttribute(new Attribute("date","11.07.2007"));
        event.appendChild("błe");
        root.appendChild(event);

        Document doc = new Document(root);

        System.out.println(doc.toXML());
        
        try
        {
            try
            {
                path = new java.io.File(".").getCanonicalPath();
                //System.out.println(path);
            }
            catch (IOException ex)
            {
                System.out.println(ex);
            }
            File tmp = new File(path + save_dir);
            tmp.mkdir();
            xmldoc = new PrintStream(path + save_dir + save_file_name + ".xml");
        }
        catch (FileNotFoundException ex)
        {
            System.out.println(ex);
        }

        try
        {
            Serializer serializer = new Serializer(xmldoc, "ISO-8859-1");
            serializer.setIndent(4);
            serializer.setMaxLength(64);
            serializer.write(doc);
        }
        catch(IOException ex)
        {
            System.err.println(ex);
        }
        xmldoc.close();
    }
}
